package com.xhu.controller;

import com.xhu.service.DecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class DecodeController {

    @Value("${conf.filePath}")
    private String filePath;

    @Autowired
    private DecodeService decodeService;

    @PostMapping("/decode")

    public String decode(MultipartFile file, String type){
        String result = null;
        String fileName = file.getOriginalFilename();
        String totalPath = filePath + "/decode/" + fileName;
        System.out.println(totalPath);
        File dest = new File(totalPath);
        try {
            //储存文件到本地
            file.transferTo(dest);
            result = decodeService.decode(totalPath,type);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
